package com.hualan.dao.impl;

import com.hualan.dao.CourierStationDao;
import com.hualan.bean.PanghuCourierStation;
import com.hualan.utils.DBUtils;

import java.util.List;
import java.util.Map;

public class CourierStationDaoImp implements CourierStationDao {


    //按照页数进行搜索
    @Override
    public List<Map<String, Object>> selectPcs(int pageNum, int pageSize) {
        List<Map<String, Object>> pcslist =DBUtils.query("select courier_station_id,courier_station_name,courier_station_image,courier_station_province,courier_station_city,courier_station_district,courier_station_address,courier_station_status,add_time,courier_station_sort,courier_station_community_id,panghu_community.community_name  from panghu_courier_station left join panghu_community on panghu_courier_station.courier_station_community_id=panghu_community.community_id limit ?,?",(pageNum -1)*pageSize,pageSize);
        return pcslist;
    }

//    public List<PanghuCourierStation> queryCondition(int pageNum, int pageSize, String courierStationName, String communityName, String startTime,String endTime) {
//        //存放参数的list集合
//        ArrayList<Object> parameterList = new ArrayList<>();
//        //初始条件
//        String conditionParameter = " where 1 = 1 ";
//        if (communityName != null && !courierStationName.equals("")) {
//            conditionParameter = conditionParameter + " and shop_name = ?";
//            parameterList.add(communityName);
//        }
//        if (communityName != null && !communityName.equals("")) {
//            conditionParameter = conditionParameter + " and shop_phone = ?";
//            parameterList.add(communityName);
//        }
//        if ((startTime != null && !startTime.equals("")) && (endTime != null && !endTime.equals(""))) {
//            conditionParameter = conditionParameter + " and add_time between ? and ? ";
//            parameterList.add(startTime);
//            parameterList.add(endTime);
//        }
//        //拼接上当前页和每页显示的数据
//        conditionParameter = conditionParameter + " limit " + pageNum + "," + pageSize;
//        String sql = "select * from panghu_shop" + conditionParameter;
//        System.out.println(sql);
//        //将查询的数据进行返回
//        return DBUtils.query(sql, PanghuShop.class, parameterList.toArray(new Object[0]));
//    }

    @Override
    public List<Map<String, Object>> selectByPcs(int pageNum, int pageSize, String courierStationName, String communityName, String startTime,String endTime) {
        String courierStationName1="%"+courierStationName+"%";
        String communityName1="%"+communityName+"%";
        List<Map<String, Object>> pcslist =DBUtils.query("select courier_station_id,courier_station_name,courier_station_image,courier_station_province,courier_station_city,courier_station_district,courier_station_address,courier_station_status,add_time,courier_station_sort,courier_station_community_id,panghu_community.community_name  from panghu_courier_station left join panghu_community on panghu_courier_station.courier_station_community_id=panghu_community.community_id where courier_station_name like ? and community_name like ? and add_time between ? and ? limit ?,?" ,courierStationName1,communityName1,startTime,endTime,(pageNum -1)*pageSize,pageSize);
        return pcslist;
    }

    //查询总数
    @Override
    public Long selectAllPcsCount() {

        Map<String,Object> map = DBUtils.queryOne("select count(*) as count from panghu_courier_station");
        Long count = null;
        if (map != null) {
            count = (Long) map.get("count");
        }
        return count;
    }

    @Override
    public PanghuCourierStation selectPcsbyId(int id) {
        return null;
    }

    @Override
    public int addPcs(PanghuCourierStation pcs) {
        int row=DBUtils.update("insert into panghu_courier_station(courier_station_name,courier_station_image,courier_station_province,courier_station_city,courier_station_district,courier_station_address) values(?,?,?,?,?,?)",pcs.getCourierStationName(),pcs.getCourierStationImage(),pcs.getCourierStationProvince(),pcs.getCourierStationCity(),pcs.getCourierStationDistrict(),pcs.getCourierStationAddress());
        return row;
    }

    @Override
    public int updatePcs(PanghuCourierStation pcs) {
        int row=DBUtils.update("update  panghu_courier_station set courier_station_name=?,courier_station_image=?,courier_station_province=?,courier_station_city=?,courier_station_district=?,courier_station_address=?,courier_station_community_id=? where courier_station_id=?",pcs.getCourierStationName(),pcs.getCourierStationImage(),pcs.getCourierStationProvince(),pcs.getCourierStationCity(),pcs.getCourierStationDistrict(),pcs.getCourierStationAddress(),pcs.getCourierStationCommunityId(),pcs.getCourierStationId());
        return row;
    }

    @Override
    public int deletePcs(int id) {
        int row=DBUtils.update("delete  from panghu_courier_station where id=?",id);
        return row;
    }
}
